package org.algorithm.落雪.数组.三月.第三周;

/**
 * @date 2022/03/17 10:08 PM
 * @description: 周五作业
 *
 *
 * url: https://leetcode-cn.com/problems/container-with-most-water/
 */
public class 盛最多水的容器 {

    public static void main(String[] args) {
        int[] nums = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(nums));
    }

    
    public static int maxArea(int[] nums){
        // 双指针

        int left = 0, right = nums.length - 1, result = 0;
        while (left < right) {
            result = nums[left] < nums[right] ? Math.max(result, (right - left) * nums[left++]):
                    Math.max(result, (right - left) * nums[right--]);
        }
        return result;
    }


}
